package com.hcyy.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hcyy.dao.CartDao;
import com.hcyy.entity.Cart;
import com.hcyy.service.CartService;

@Service
@Transactional
public class CartServiceImpl implements CartService {

	@Autowired
	private CartDao cartDao;
	@Override
	public int addCart(Cart cart) {
		Integer FQty=cartDao.findCart(cart.getSpid(), cart.getDwbh(), cart.getSjid());
		int affectRows = 0;
		if(FQty!=null){
			affectRows = cartDao.updateCart(cart);
		}else{
			affectRows = cartDao.insertCart(cart);
		}
		return affectRows;
	}
	@Override
	public List<Cart> findCartByUserID(String userid,Integer sjid) {
		return cartDao.findCartByUserID(userid,sjid);
	}
	@Override
	public void delCart(Long cid) {
		cartDao.deleteCartByCid(cid);
	}
	@Override
	public void modCart(Long cid, int FQty,double FPrice) {
		 cartDao.updateCartByCid(cid, FQty,FPrice);
	}
	@Override
	public List<Cart> findCartByCidArray(String[] cids,String dwbh,Integer sjid) {
		return cartDao.findCartByCidArray(cids,dwbh,sjid);
	}
	@Override
	public void updateCartPrice(Long cid, Double price) {
		cartDao.updateCartPrice(cid, price);
	}

}
